package com.luyuan.crm.promotion.internal;

import java.util.List;

import org.hibernate.criterion.Order;

import com.luyuan.crm.promotion.Promotion;
import com.luyuan.crm.promotion.PromotionService;
import com.ruijie.foundation.dao.extend.support.HibernateEntityExtendDao;
import com.ruijie.foundation.query.Page;
import com.ruijie.foundation.query.criteria.CriteriaQueryTemplate;
import com.ruijie.foundation.query.criteria.CriteriaTemplate;

public class PromotionServiceImpl extends HibernateEntityExtendDao<Promotion> implements PromotionService {

    @Override
    public Page pagedQuery(CriteriaTemplate criteria, int pageNo, int pageSize, List<Order> orders) {
        CriteriaQueryTemplate qt = new CriteriaQueryTemplate(getSessionFactory());
        return qt.pagedQuery(criteria, pageNo, pageSize, orders);
    }

    @Override
    public void addPromotion(Promotion promotion) {
        save(promotion);
    }

    @Override
    public void updatePromotion(Promotion promotion) {
        update(promotion);
    }

    @Override
    public void deletePromotion(String id) {
        remove(id);
    }

    @Override
    public Promotion getPromotionById(String id) {
        return safeGet(id);
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<Promotion> findEffectivePromotion() {
        return find("from Promotion where startDate <= now() and now() <= endDate order by endDate asc");
    }

}
